<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/6/28
 * Time: 14:54
 */

namespace app\common\model\mall;

use app\common\model\TimeModel;


class Item extends TimeModel
{
    protected $deleteTime = 'delete_time';


    /**图片获取器
     * @param $value
     * @return string
     */
    public function setImageAttr($value){

        return implode(',',$value);
    }

    public function getImageAttr($value){
        return explode(',',$value);
    }

    public function getContentAttr($value){
        return htmlspecialchars_decode($value);
    }


    //商品所属分类
    public function category()
    {
        return $this->belongsTo('app\common\model\common\Categories','category_id','id')->field('id,name');
    }

    //商品所属商家
    public function store()
    {
        return $this->belongsTo('app\common\model\mall\Store','store_id','id')->field('id,name,type');
    }

    //获取参营销活动的商品
    public function market()
    {
        return $this->belongsTo('app\common\model\market\MarketItem','item_id','id');
    }

    //商品下所有的sku
    public function ItemSku()
    {
        return $this->hasMany('app\common\model\mall\ItemSku','goods_id','id');
    }
    //商品下所有的ItemSkuSpec
    public function ItemSkuSpec()
    {
        return $this->hasMany('app\common\model\mall\ItemSkuSpec','goods_id','id');
    }

}